import Vue from 'vue'
import Vuex from 'vuex'
import { getList, loginPost } from '@/api/user'
import { setToken, getToken } from '@/utils/storage'
import user from './user'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: getToken(),
    obj: {}
  },
  getters: {
  },
  mutations: {
    changelogin (state, token) {
      state.token = token
      setToken(token)
    },
    // getlist(state,obj){
    //   state.obj = obj
    // }
  },
  actions: {
    async asynclogin ({ commit }, rouleform) {
      const res = await loginPost(rouleform)
      console.log(res);
      commit('changelogin', res.data.token)
    },
    // async getLists ({ commit }) {
    //   const res2 = await getList()
    //   console.log(res2);
    //   commit('getlist',res2.data)
    // },
  },
  modules: {
    user
  }
})
